﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Recursos.Model
{
    public class CursoModel
    {
        public IList<Curso> CargarCurso()
        {
            var datacontext = new DataClassesRecursosDataContext();
            var cursos = new Repository<Curso>(datacontext);
            return cursos.GetAll().ToList();
        }
        public IList<Curso> CargarCursoCarrera(int idcarrera)
        {
            var datacontext = new DataClassesRecursosDataContext();
            var cursos = new Repository<Curso>(datacontext);
            return cursos.GetAll().Where(s=>s.Carrera.id==idcarrera).ToList();
        }

        public Curso GetCursoById(int id)
        {
            var datacontext = new DataClassesRecursosDataContext();
            var cursos = new Repository<Curso>(datacontext);
            return cursos.GetById(id);
        }

        public Curso GetCursoByCodigo(string codigo)
        {
            try
            {
                var datacontext = new DataClassesRecursosDataContext();
                var cursos = new Repository<Curso>(datacontext);
                return cursos.SearchOne(c => c.Codigo.Equals(codigo));
            }
            catch (Exception)
            {

                return null;
            }
            
        }
    }
}